home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / MSG Graphic Effects 1.0 Source / Dissolve wipe.c < prev    next >
Text File  |  1993-08-21  |  4KB  |  121 lines

  1. /*******************************************************************************
  2.  * Copywrite © 1992-1993 David S. Blumenthal                                   *
  3.  *                                                                             *
  4.  * This file is provided as is, and may be freely distributed unaltered.  This *
  5.  * message must accompany any copy of this file.  This file may be used or     *
  6.  * modified for use for a non-commercial product provided that appropriate     *
  7.  * credit is given to the author named above.                                  *
  8.  * Commercial use of this source code is prohibited.                           *
  9.  ******************************************************************************/
  10.  
  11. #include "msg misc.h"
  12. #include "msg timing.h"
  13.  
  14. #define CorrectTime 2
  15.  
  16. void DissolveBox(GrafPtr, Rect*, Rect*);
  17. void DissolveWipe(GrafPtr);
  18.  
  19. void DissolveBox(GrafPtr newImage, Rect *source, Rect *dest)
  20. {
  21.     long        offRowBytes, sizeOfOff;
  22.     Ptr            myBits;
  23.     Rect        bRect;
  24.     GrafPort    myGrafPort;
  25.     GrafPtr        myGrafPtr;
  26.     RgnHandle    oldClipRgn;
  27.     int            i, j;
  28.     Pattern        thePattern;
  29.     char        order[16];
  30.     long        randtemp;
  31.     char        ordertemp;
  32.     
  33.     /* the dissolve effect works by creating a random set of patterns which sum
  34.     (OR) to a black pattern.  We make another offscreen bitmap and fill it with
  35.     the pattern at each stage, and use it as a mask for the bitcopy.  Here, we
  36.     create the offscreen bitmap. */
  37.     
  38.     SetPort(newImage);
  39.     bRect = *source;
  40.     myGrafPtr = &myGrafPort;
  41.     OpenPort(myGrafPtr);
  42.     offRowBytes = (((source->right - source->left) + 15) >> 4) << 1;
  43.     sizeOfOff = (long)(source->bottom - source->top) * offRowBytes;
  44.     OffsetRect(&bRect, -bRect.left, -bRect.top);
  45.     myBits = NewPtr(sizeOfOff);
  46.     if(myBits == 0L)
  47.         ErrorString("\pThere is not enough memory.  ", "\p");
  48.     myGrafPort.portBits.baseAddr = myBits;
  49.     myGrafPort.portBits.rowBytes = offRowBytes;
  50.     myGrafPort.portBits.bounds = bRect;
  51.     myGrafPort.portRect = bRect;
  52.     oldClipRgn = myGrafPort.clipRgn;
  53.     myGrafPort.clipRgn = gMainWindow->visRgn;
  54.     
  55.     for(i = 0; i < 16; i++)
  56.         order[i] = i;
  57.     
  58.     /* this randomly shuffles the order in which the pattern bits will appear */
  59.     for(i = 15; i >= 0; i--) {
  60.         randtemp = (((long)Random() + 32767) * (i + 1)) / 65535;
  61.         ordertemp = order[randtemp];
  62.         order[randtemp] = order[i];
  63.         order[i] = ordertemp;
  64.     }
  65.     
  66.     for(i = 0; i < 16; i++)
  67.     {
  68.         StartTiming();
  69.         SetPort(myGrafPtr);
  70.         
  71.         for(j = 0; j < 8; j++) thePattern[j] = 0;
  72.         thePattern[order[i] >> 2] = 1 << (order[i] & 0x03);
  73.         thePattern[order[i] >> 2] |= 16 << (order[i] & 0x03);
  74.         thePattern[(order[i] >> 2) + 4] = 1 << (order[i] & 0x03);
  75.         thePattern[(order[i] >> 2) + 4] |= 16 << (order[i] & 0x03);
  76.         
  77.         FillRect(&bRect, &thePattern);
  78.         
  79.         SetPort(gMainWindow);
  80.         
  81.         CopyMask(&(newImage->portBits), &(myGrafPtr->portBits),
  82.                 &(gMainWindow->portBits), source, &bRect, dest);
  83.         TimeCorrection(CorrectTime);
  84.     }
  85.     
  86.     myGrafPort.clipRgn = oldClipRgn;
  87.     ClosePort(myGrafPtr);
  88.     DisposPtr(myBits);
  89. }
  90.  
  91. /* the actual dissolve wipe splits the screen into 9 blocks, and dissolves
  92. the source onto the destination by blocks in random order.  That way, each
  93. dissolve is faster, and the whole effect is more interesting. */
  94. void DissolveWipe(GrafPtr myGrafPtr)
  95. {
  96.     char    order[9];
  97.     char    ordertemp;
  98.     int        i;
  99.     long    randtemp;
  100.     Rect    source, dest;
  101.     
  102.     for(i = 0; i < 9; i++)
  103.         order[i] = i;
  104.     
  105.     for(i = 8; i >= 0; i--) {
  106.         randtemp = (((long)Random() + 32767) * (i + 1)) / 65535;
  107.         ordertemp = order[randtemp];
  108.         order[randtemp] = order[i];
  109.         order[i] = ordertemp;
  110.     }
  111.     
  112.     for(i = 0; i < 9; i++) {
  113.         source.top = (order[i] / 3) * (MAIN_WINDOW_HEIGHT / 3);
  114.         source.left = (order[i] % 3) * (MAIN_WINDOW_WIDTH / 3);
  115.         source.bottom = (((order[i] / 3) + 1) * MAIN_WINDOW_HEIGHT) / 3;
  116.         source.right = (((order[i] % 3) + 1) * MAIN_WINDOW_WIDTH) / 3;
  117.         
  118.         DissolveBox(myGrafPtr, &source, &source);
  119.     }
  120. }
  121.